home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 003-desktop.lzm / usr / bin / kactivate < prev    next >
Encoding:
Text File  |  2008-05-04  |  2.7 KB  |  75 lines

  1. #!/bin/bash
  2. # This script is used in KDE to provide a GUI for 'activate'
  3. # It has the same syntax like 'activate', moreover it accepts HTTP addresses
  4. # to be mounted remotely using httpfs
  5. # (you may kactivate a LZM module over HTTP, no need to download it!)
  6.  
  7. PATH=.:$(dirname $0):/usr/lib:$PATH
  8. . liblinuxlive || exit 127
  9.  
  10. # make sure to work only with *.lzm files
  11. while [ "$(echo "$1" | grep '.lzm$')" = "" -a "$1" != "" ]; do shift; done
  12.  
  13. FILE="$1"
  14.  
  15. if [ "$FILE" = "" ]; then
  16.    FILE=$(kdialog --icon folder_open --getopenurl "" "*.lzm" --title "Select LZM module")
  17.    if [ $? -ne 0 ]; then exit 1; fi
  18.    FILE=$(echo "$FILE" | sed -r "s,file://,,")
  19. fi
  20.  
  21. BASE=$(basename "$FILE" 2>/dev/null)
  22.  
  23. # if the module is already activated, suggest deactivation
  24. if ismountpoint "/mnt/live/memory/images/$BASE"; then
  25.    kdialog --icon help --title "Deactivate the module?" --warningyesno "$BASE:\nModule is already activated. Deactivate?"
  26.    if [ $? -eq 0 ]; then deactivate $BASE; exit 0; fi
  27.    exit 2
  28. fi
  29.  
  30. SLIK=${FILE:0:4}
  31.  
  32. # handle slik (Slax Klik) and HTTP requests/urls
  33. if [ "$SLIK" = "slik" -o "$SLIK" = "http" ]; then
  34.  
  35.    # if a module is loaded from untrusted site (everything else than slax.org, ask for confirmation)
  36.    DOMAIN=$(echo "$FILE" | cut -b 8- | egrep -o "^(www.)?([^/]+)")
  37.    DOMAIN=${DOMAIN##www.}
  38.    if [ "$DOMAIN" != "slax.org" ]; then
  39.       kdialog --icon configure --dontagain "kactivate:trust-$DOMAIN" --title "unsafe domain $DOMAIN" --warningyesno "Warning! You are about to load a module from $DOMAIN...\nThis may be unsafe. Are you sure?"
  40.       if [ $? -ne 0 ]; then exit 127; fi
  41.    fi
  42.  
  43.    MNT="/mnt/live/memory/httpfs/$BASE"
  44.    mkdir -p "$MNT"
  45.    kdialog --passivepopup "$BASE: module insertion in progress, wait please..." 10000 & KILLPID=$!
  46.    ERR=$(httpfs http${FILE:4} "$MNT" 2>&1)
  47.    if [ $? -ne 0 ]; then
  48.       kill $KILLPID
  49.       kdialog --icon error --title "network error" --error "Can't mount the module remotely.\nError message: $ERR\n\nTry to download the module to your computer."
  50.       exit 128;
  51.    fi
  52.    echo "http${FILE:4}" >$MNT/slik.url
  53.    kill $KILLPID
  54.    FILE="$MNT/$BASE"
  55. fi
  56.  
  57. # show info message and remember PID of the process (we'll need to kill the message later on)
  58. kdialog --passivepopup "$BASE: module insertion in progress, wait please..." 10000 & KILLPID=$!
  59.  
  60. # insert the module to live filesystem
  61. activate -k "$FILE"
  62.  
  63. if [ $? -ne 0 ]; then
  64.    kill $KILLPID
  65.    kdialog --icon error --title "unknown error" --error "Some error occured while activating the module."
  66.    exit 3
  67. else
  68.    # Rebuild the system configuration cache for KDE (mainly to update KDE menu)
  69.    kbuildsycoca 2>/dev/null
  70.    kill $KILLPID
  71.    kdialog --passivepopup "Well done! $BASE: module activated successfully." 5 &
  72. fi
  73.  
  74. exit 0
  75.